package cn.edu.nhic.order;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.io.IOException;

import cn.edu.nhic.order.utils.Constant;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView imageView=this.findViewById(R.id.imageView);
        Glide.with(this)
                .load(getResources()).into(imageView);

        //网络方法步骤
        //创建1.okhttpclient 对象
        OkHttpClient client=new OkHttpClient();
        //2.构建Request对象
        String url=Constant.WEB_SITE+Constant.REQUEST_SHOP_URL;
        Request request = new Request.Builder()
//                .url("http://192.168.3.195:8080/order/index.html")
        .url("http://192.168.3.195:8080/order/shop_list_data.json")
//                .url("http://www.ryweike.com/")
        .get()
        .build();
        //3.通过okhttpclient 和 request 构造Call
        Call call=client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){
                    String res=response.body().string();
                    Log.i("========== MainActivity ============",res);
                    System.out.println("hahahha>>>>>>"+res);
                }else{

                }
            }
        });
    }
}